<?php
/**
 * @file myattention.php
 * @author LinLin
 * @date 2016年4月27日 下午12:31:30
 * @brief 
 */
namespace haibao\user\business;

use haibao\user\business\UserInfo as UserInfoBusiness;


class MyAttention extends \haibao\user\business\Base{
    
    
    /**
     * 我的关注列表
     * @param  $attentionType  品牌 明星 设计师 博主 美剧
     * $celebrityAttentionFilter 
     * $attentionType 类型
     * $picSize 图片大小
     */
    //明星
    public static function getMyStarAttention($celebrityAttentionFilter,$attentionType,$picSize){
        $celebrityList = \haibao\cms\business\Celebrity::getAll($celebrityAttentionFilter);
        if($celebrityList){
            $celebrityList = self::getAttentionSpaceUrl($celebrityList,$attentionType);
            $celebrityList = self::getAttentionImageUrl($celebrityList,$attentionType,$picSize);
        }
        return $celebrityList;
    }
    

    //品牌
    public static function getMyBrandAttention($brandAttentionFilter,$attentionType,$picSize){
        $brandList = \haibao\cms\business\Brand::getBrandByFilter($brandAttentionFilter);
        if($brandList){
            $brandList = self::getAttentionSpaceUrl($brandList, $attentionType);
            $brandList = self::getAttentionImageUrl($brandList,$attentionType,$picSize);
        }
        return $brandList;
    }

    
    //设计师
    public static function getMyDesignerAttention($designerAttentionFilter,$attentionType,$picSize){
        $designerList = \haibao\cms\business\Designer::getDesignerByFilter($designerAttentionFilter,false);
        if($designerList){
            $designerList = self::getAttentionSpaceUrl($designerList, $attentionType);
            $designerList =  self::getAttentionImageUrl($designerList,$attentionType,$picSize);
        }
        return $designerList;
    }
    
    
    //美剧
    public static function getMyAmericanAttention($americanAttentionFilter,$attentionType,$picSize){
        $americanList = \haibao\cms\business\americandrama\AmericanDefine::getAmericanByFilter($americanAttentionFilter,false);
        $article = new \haibao\www\sites\common\Article();
        if($americanList){
            foreach($americanList as $key=>$info){
                $americanList[$key]->AmericanAttentionRelated->AvatarUrl = $article->getImageRealUrl($info->AmericanAttentionRelated->AvatarUrl, $picSize['width'], $picSize['height'], 100, 0);
                $americanList[$key]->AmericanAttentionRelated->AmericanUrl = \haibao\classlibrary\www\Config::getConfig(\haibao\classlibrary\www\Config::CLASSLIBRARY_CONFIG_TV_HOST).'meiju/'.$info->AmericanAttentionRelated->Id.'/';
            }
        }
        return $americanList;
    }
    
    //博主
    public static function getMyBloggerAttention($userAttentionFilter,$attentionType){
        $bolggerList = \haibao\user\business\UserInfo::getFriendList($userAttentionFilter);
        if($bolggerList){
            foreach($bolggerList as $key=>$val){
                $bolggerList[$key]->UserList->SpaceUrl = \haibao\classlibrary\www\Config::getConfig(\haibao\classlibrary\www\Config::CLASSLIBRARY_CONFIG_HOST_USER).'/space/'.$val->AttentionUserId.'/';
            }
        }
        return $bolggerList;
    }
    
    /**
     * 获取搜索出的列表相关信息
     */
    
    public static function getMySearchAttention($infoFilter,$attentionType,$picSize){
        if($attentionType != \haibao\www\model\data\Favorite::ATTENTION_TYPE_BLOGGER){
            $infoList = \haibao\cms\business\Celebrity::getOne($infoFilter);
        }
        $article = new \haibao\www\sites\common\Article();
        if($attentionType == \haibao\www\model\data\Favorite::ATTENTION_TYPE_STAR){
            $imageId = $infoList->CelebrityInformation->ImageId;
            if($imageId){
                $imageUrl = \haibao\cms\business\ImageLibrary::getImageUrlById($imageId);
                $infoList->CelebrityInformation->ImageUrl = $article->getImageRealUrl($imageUrl[$imageId], $picSize['width'], $picSize['height'], 100, 0);
            }else{
                $infoList->CelebrityInformation->ImageUrl = '';
            }
            $topicIdArr = \haibao\cms\business\Tag::getTopicIdByTagId($infoList->TagId);
            $infoList->TopicId = $topicIdArr[$infoList->TagId];
            $infoList->CelebrityInfo = \haibao\classlibrary\www\Config::getConfig(\haibao\classlibrary\www\Config::CLASSLIBRARY_CONFIG_HOST_STARS).'/star/'.$infoList->TopicId.'/'; //url
        }elseif($attentionType == \haibao\www\model\data\Favorite::ATTENTION_TYPE_BRAND){
            $imageId = $infoList->ImgId;
            if($imageId){
                $imageUrl = \haibao\cms\business\ImageLibrary::getImageUrlById($imageId);
                $infoList->Image = $article->getImageRealUrl($imageUrl[$imageId], $picSize['width'], $picSize['height'], 100, 0);
            }else{
                $infoList->Image = '';
            }
            $topicIdArr = \haibao\cms\business\Tag::getTopicIdByTagId($infoList->TagId);
            $infoList->BrandUrl = \haibao\classlibrary\www\Config::getConfig(\haibao\classlibrary\www\Config::CLASSLIBRARY_CONFIG_HOST_BRANDS).'/brand/'.$topicIdArr[$infoList->TagId].'/'; //url
           
        }elseif($attentionType == \haibao\www\model\data\Favorite::ATTENTION_TYPE_DESIGNER){
            $imageId = $infoList->ImgId;
            if($imageId){
                $imageUrl = \haibao\cms\business\ImageLibrary::getImageUrlById($imageId);
                $infoList->ImageUrl = $article->getImageRealUrl($imageUrl[$imageId], $picSize['width'], $picSize['height'], 100, 0);
            }else{
                $infoList->ImageUrl = '';
            }
            $topicIdArr = \haibao\cms\business\Tag::getTopicIdByTagId($infoList->TagId);
            $infoList->DesignUrl = \haibao\classlibrary\www\Config::getConfig(\haibao\classlibrary\www\Config::CLASSLIBRARY_CONFIG_HOST_DESIGNER).'/designer/'.$infoList->TopicId.'/'; //url
        }elseif($attentionType == \haibao\www\model\data\Favorite::ATTENTION_TYPE_AMERICAN){
            $infoList->AvatarUrl = $article->getImageRealUrl($infoList->AvatarUrl, $picSize['width'], $picSize['height'], 100, 0);;
            $infoList->AmericanUrl = \haibao\classlibrary\www\Config::getConfig(\haibao\classlibrary\www\Config::CLASSLIBRARY_CONFIG_TV_HOST).'meiju/'.$infoList->Id.'/';
        }elseif($attentionType == \haibao\www\model\data\Favorite::ATTENTION_TYPE_BLOGGER){
            $infoList = UserInfoBusiness::getFriendList($infoFilter);
            $infoList[0]->SpaceUrl = \haibao\classlibrary\www\Config::getConfig(\haibao\classlibrary\www\Config::CLASSLIBRARY_CONFIG_HOST_USER).'/space/'.$infoList[0]->Id.'/';
        }
        return $infoList;
    }
    
    
    /**
     * 获取头像地址
     * @param unknown $infoList
     * @param unknown $attentionType
     */
    private static function getAttentionImageUrl($infoList,$attentionType,$picSize){
        foreach($infoList as $key=>$info){
            if($attentionType == \haibao\www\model\data\Favorite::ATTENTION_TYPE_STAR){
                $imageIds[] = $info->CelebrityAttenionImage->ImageId;
            }elseif($attentionType == \haibao\www\model\data\Favorite::ATTENTION_TYPE_BRAND){
                $imageIds[] = $info->BrandAttentionRelated->ImgId;
            }elseif($attentionType == \haibao\www\model\data\Favorite::ATTENTION_TYPE_DESIGNER){
                $imageIds[] = $info->DesignerAttentionRelated->ImgId;
            }
    
        }
        if($imageIds){
            $imageUrl = \haibao\cms\business\ImageLibrary::getImageUrlById($imageIds);
            $article = new \haibao\www\sites\common\Article();
            foreach($infoList as $key=>$info){
                if($attentionType == \haibao\www\model\data\Favorite::ATTENTION_TYPE_STAR){
                    if(isset($imageUrl[$info->CelebrityAttenionImage->ImageId])){
                        $infoList[$key]->CelebrityAttenionImage->ImageUrl = $article->getImageRealUrl($imageUrl[$info->CelebrityAttenionImage->ImageId], $picSize['width'], $picSize['height'], 100, 0);
                    }
                }elseif($attentionType == \haibao\www\model\data\Favorite::ATTENTION_TYPE_BRAND){
                    if(isset($imageUrl[$info->BrandAttentionRelated->ImgId])){
                        $infoList[$key]->BrandAttentionRelated->Image = $article->getImageRealUrl($imageUrl[$info->BrandAttentionRelated->ImgId], $picSize['width'], $picSize['height'], 100, 0);
                       
                    }
                }elseif($attentionType == \haibao\www\model\data\Favorite::ATTENTION_TYPE_DESIGNER){
                    if(isset($imageUrl[$info->DesignerAttentionRelated->ImgId])){
                        $infoList[$key]->DesignerAttentionRelated->ImageUrl = $article->getImageRealUrl($imageUrl[$info->DesignerAttentionRelated->ImgId], $picSize['width'], $picSize['height'], 100, 0);
                    }
                }
    
            }
        }
        return $infoList;
    }
    
    /**
     * 获取空间地址
     * @param unknown $infoList
     * @param unknown $attentionType
     */
    private static function getAttentionSpaceUrl($infoList,$attentionType){
        if($attentionType == \haibao\www\model\data\Favorite::ATTENTION_TYPE_DESIGNER){
            foreach($infoList as $key=>$val){
                $infoList[$key]->DesignerAttentionRelated->DesignUrl =  \haibao\classlibrary\www\Config::getConfig(\haibao\classlibrary\www\Config::CLASSLIBRARY_CONFIG_HOST_DESIGNER).'/designer/'.$val->DesignerAttentionRelated->TopicId.'/';
            }
        }else{
            foreach($infoList as $key=>$val){
                if($attentionType == \haibao\www\model\data\Favorite::ATTENTION_TYPE_STAR){
                    $tagIdArr[] = $val->CelebrityAttenionRelated->TagId;
                }elseif($attentionType == \haibao\www\model\data\Favorite::ATTENTION_TYPE_BRAND){
                    $tagIdArr[] = $val->BrandAttentionRelated->TagId;
                }
            }
            if($tagIdArr){
                $topicArr = \haibao\cms\business\Tag::getTopicIdByTagId($tagIdArr);
                foreach($infoList as $key=>$val){
                    if($attentionType == \haibao\www\model\data\Favorite::ATTENTION_TYPE_STAR){
                        if(isset($topicArr[$val->CelebrityAttenionRelated->TagId])){
                            $infoList[$key]->CelebrityAttenionRelated->TopicId = $topicArr[$val->CelebrityAttenionRelated->TagId];
                            $infoList[$key]->CelebrityAttenionRelated->CelebrityUrl =  \haibao\classlibrary\www\Config::getConfig(\haibao\classlibrary\www\Config::CLASSLIBRARY_CONFIG_HOST_STARS).'/star/'.$topicArr[$val->CelebrityAttenionRelated->TagId].'/';
                        }
                    }elseif($attentionType == \haibao\www\model\data\Favorite::ATTENTION_TYPE_BRAND){
                        if(isset($topicArr[$val->BrandAttentionRelated->TagId])){
                            $infoList[$key]->BrandAttentionRelated->BrandUrl =  \haibao\classlibrary\www\Config::getConfig(\haibao\classlibrary\www\Config::CLASSLIBRARY_CONFIG_HOST_BRANDS).'/brand/'.$topicArr[$val->BrandAttentionRelated->TagId].'/';
                        }
                    }
                }
            }
        }
        return $infoList;
    }
   
} 